#include<iostream>
#include<pthread.h>
#include<mutex>
#include<queue>
#include<functional>
using namespace std;
class singleton
{
public:
	static singleton* getinstance()
	{
		if (ptr == nullptr)
		{
			mtx.lock();
			if (ptr == nullptr)
				ptr = new singleton();
			mtx.unlock();
		}
		return ptr;
	}

	class cb
	{
	public:
		~cb()
		{
			if (ptr)
			{
				cout << "析构" << endl;
				delete ptr;
				ptr = nullptr;
			}
		}
	};

	static cb b;
private:
	singleton()
	{
		cout << "构造" << endl;
	}

	singleton(const singleton&) = delete;
	singleton& operator=(const singleton&) = delete;

	static singleton* ptr;
	static mutex mtx;
};

mutex singleton::mtx;
singleton* singleton::ptr = nullptr;
singleton::cb b;